{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑项目</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">项目名字：</label>
                            <div class="layui-input-block">
                                <input type="text" name="pro_name" class="layui-input" value="{$info.pro_name}" lay-verify="required" maxlength="50" />
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">关联公司：</label>
                            <div class="layui-input-block">
                                <select name="pro_c_id" lay-search="" id="company"  lay-filter="company"  lay-verify="required">
                                    <option value="">---- 请选择公司 ----</option>
                                    {foreach name="coms" item="c"}
                                    <option value="{$c.c_id}" {$info.pro_c_id == $c.c_id ? 'selected' : ''}>{$c.c_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">关联产品：</label>
                            <div class="layui-input-block">
                                <select name="pro_cp_id" lay-search="" id="company_product"  lay-verify="required">
                                    <option value="">---- 请选择产品 ----</option>
                                    {foreach name="product" item="p"}
                                    <option value="{$p.cp_id}" {$info.pro_cp_id == $p.cp_id ? 'selected' : ''}>{$p.cp_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">关联业务员：</label>
                            <div class="layui-input-block">
                                <select name="pro_user_id" lay-search="" id="company_user"  lay-verify="required">
                                    <option value="">---- 请选择业务员 ----</option>
                                    {foreach name="users" item="u"}
                                    <option value="{$u.user_id}" {$info.pro_user_id == $u.user_id ? 'selected' : ''}>{$u.user_username}({$u.user_phone})</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">开始时间：</label>
                            <div class="layui-input-block">
                                <input type="text" name="pro_start_time" value="{$info.pro_start_time}" onclick="wk.lay_date(this);" class="layui-input" lay-verify="required" readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">结束时间：</label>
                            <div class="layui-input-block">
                                <input type="text" name="pro_end_time" value="{$info.pro_end_time}" onclick="wk.lay_date(this);" class="layui-input" lay-verify="required" readonly>
                            </div>
                        </div>
                        <input type="hidden" value="{$info.pro_id}" name="pro_id">
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                                </button>
                                <button class="layui-btn layui-btn-primary" onclick="wk.layer_close('close')">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
</body>
</html>
<script>
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
        form.on('submit(component-form-element)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('proEdit')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            wk.layer_close();
                        })
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
        form.on('select(company)', function(data){
            getUsersByCom(data.value);
        });
        function getUsersByCom(cid){
            $.ajax({
                url:"{:url('admin/Project/getUsers')}",
                dataType:"json",
                data:'cid='+cid,
                type:'post',
                success:function(res){
                    var opt = '';
                    $.each(res.msg,function(key,vo){
                        opt = opt+"<option value="+vo.user_id+">"+vo.user_username+"("+vo.user_phone+")</option>";
                    });
                    $("#company_user").empty();
                    $("#company_user").append('<option value="">---- 请选择业务员 ----</option>');
                    $("#company_user").append(opt);
                    form.render('select');
                    var opt = '';
                    $.each(res.product,function(key,vo){
                        opt = opt+"<option value="+vo.cp_id+">"+vo.cp_name+"</option>";
                    });
                    $("#company_product").empty();
                    $("#company_product").append('<option value="">---- 请选择产品 ----</option>');
                    $("#company_product").append(opt);
                    form.render('select');
                }
            })
        }
    });
</script>